package huawei.nk;

import java.util.Scanner;

public class Sodoku {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
            int[][] sodoku = new int[9][9];
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    sodoku[i][j]=scanner.nextInt();
                }
            }
            due(sodoku);
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    System.out.print(sodoku[i][j]+" ");
                }
                System.out.println();
            }
        }

    }
    public static void  due(int[][] sodoku){
        dfs(sodoku,0,0);
    }

    public static boolean dfs(int[][] sodoku,int x,int y){
        // 找下一个空元素
        int i=x;
        int j=y;
        boolean find=false;
        for (; i < 9; i++) {
            for (; j < 9; j++) {
                if(sodoku[i][j]==0){
                    find=true;
                    break;
                }
            }
            if(find){
                break;
            }
        }
        if(!find){
            return false;
        }
        boolean[] data = new boolean[10];
        data[0]=true;
        for (int k = 0; k < 9; k++) {
            //
            data[sodoku[i][k]]=true;
            data[sodoku[k][j]]=true;
        }
        int sI= i-i%3;
        int sJ= j-j%3;
        for (int k = sI; k <sI+3; k++) {
            for (int l = sJ; l <sJ+3 ; l++) {
                data[sodoku[k][l]]=true;
            }
        }
        for (int k = 1; k <= 9; k++) {
            // todo check
            if(data[k]){
                continue;
            }
            sodoku[i][j]=k;
           if(dfs(sodoku,i,j)){
               return true;
           }
           sodoku[i][j]=0;
        }
        return false;
    }
}
